package com.sir.tao.carhire.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sir.tao.carhire.dao.ContractDao;
import com.sir.tao.carhire.entity.table.ContractEntity;
import com.sir.tao.carhire.service.ContractService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dyy
 * @data 2021/12/24 22:36
 * @description:
 */
@Service("contractService")
public class ContractServiceImpl extends ServiceImpl<ContractDao, ContractEntity> implements ContractService {

    @Resource
    private ContractDao contractDao;

    @Override
    public int add(ContractEntity contractEntity) {
        return contractDao.add(contractEntity);
    }

    @Override
    public int deleteContractById(String contractId) {
        return contractDao.deleteById(contractId);
    }

    @Override
    public List<ContractEntity> getAll(ContractEntity contractEntity) {
        return contractDao.getAll(contractEntity);
    }

    @Override
    public int put(ContractEntity contractEntity) {
        return contractDao.put(contractEntity);
    }

    @Override
    public int examineContractById(String contractId) {
        return contractDao.examineContractById(contractId);
    }

    @Override
    public void contractSuccess(String contractId) {

        //合同完成
        LambdaUpdateWrapper<ContractEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(ContractEntity::getId,contractId);
        lambdaUpdateWrapper.set(ContractEntity::getStatus,5);
        update(lambdaUpdateWrapper);
    }

    @Override
    public ContractEntity getOne(String contractId) {
        return contractDao.getOne(contractId);
    }

    @Override
    public List<ContractEntity> contractMy(String userId) {
        return contractDao.contractMy(userId);
    }

}
